int DecompressDailyFile(char *src,char *dest) { HANDLE hFileIn,hFileOut; // int i,j,k; int result=0; unsigned char *buf,*tmpbuf; int srclen,destlen; DWORD nNumberOfBytesRead,nNumberOfBytesWritten; //open src file hFileIn=CreateFile(src,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFileIn==INVALID_HANDLE_VALUE) { printf("open src file %s error\n",src); goto allexit; } //try to open dest file hFileOut=CreateFile(dest,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if(hFileOut==INVALID_HANDLE_VALUE) {//create file error printf("create dest file %s error\n",dest); goto closesrc; } srclen=GetFileSize(hFileIn,0)-4;//file size - head size=data size //read head ReadFile(hFileIn,&destlen,4,&nNumberOfBytesRead,NULL); //printf("\n\nzlz%s %s %d\n\n",src,dest,destlen); if(destlen==0)//file size is 0,then return { result++; goto closedest; } //alloc mem to hold data buf=(unsigned char*)HeapAlloc(hHeap,HEAP_NO_SERIALIZE,srclen); if(buf==NULL) { printf("alloc memory error\n"); goto closedest; } //alloc mem to hold decompressed data tmpbuf=(unsigned char*)HeapAlloc(hHeap,HEAP_NO_SERIALIZE,destlen); if(tmpbuf==NULL) { printf("alloc memory error\n"); goto freebuf; } //read data to buf ReadFile(hFileIn,buf,srclen,&nNumberOfBytesRead,NULL); //decompress if((pDecompressDaily)(buf,srclen,tmpbuf,&destlen)) {//decompress ok,then write to file WriteFile(hFileOut,tmpbuf,destlen,&nNumberOfBytesWritten,0); result++;//set result } else {// decompress error printf("decompress %s error\n",src); } //free tmpbuf HeapFree(hHeap,HEAP_NO_SERIALIZE,tmpbuf); freebuf: HeapFree(hHeap,HEAP_NO_SERIALIZE,buf); closedest: CloseHandle(hFileOut); closesrc: CloseHandle(hFileIn); allexit: return result; } int DecompressMinuteFile(char *src,char *dest) { HANDLE hFileIn,hFileOut; int i; int result=0; unsigned char *buf,*tmpbuf; int srclen,destlen; SHORT head[31*2]; DWORD nNumberOfBytesRead,nNumberOfBytesWritten; //open src file hFileIn=CreateFile(src,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFileIn==INVALID_HANDLE_VALUE) { printf("open src file %s error\n",src); goto allexit; } //try to open dest file hFileOut=CreateFile(dest,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if(hFileOut==INVALID_HANDLE_VALUE) {//if dest does not exist,create a new one printf("create dest file %s error\n",dest); goto closesrc; } //read head ReadFile(hFileIn,head,31*4,&nNumberOfBytesRead,NULL); for(i=0;i<31;i++) { if(head[i*2]!=0) { destlen=head[i*2]; srclen=head[i*2+1]; buf=(unsigned char*)HeapAlloc(hHeap,0,srclen); if(buf==NULL) { goto closedest; } tmpbuf=(unsigned char*)HeapAlloc(hHeap,0,destlen); if(tmpbuf==NULL) { goto freebuf; } ReadFile(hFileIn,buf,srclen,&nNumberOfBytesRead,NULL); if((pDecompressMinute)(buf,srclen,tmpbuf,&destlen)) { WriteFile(hFileOut,tmpbuf,destlen,&nNumberOfBytesWritten,0); } else { printf("decompress %s error\n",src); goto freebuf1; } HeapFree(hHeap,0,tmpbuf); HeapFree(hHeap,0,buf); } } result++; goto closedest; freebuf1: HeapFree(hHeap,0,tmpbuf); freebuf: HeapFree(hHeap,0,buf); closedest: CloseHandle(hFileOut); closesrc: CloseHandle(hFileIn); allexit: return result; }
You need to enable Javascript in your browser to edit pages.
help on how to format text
网上找到的,还没有看
int DecompressDailyFile(char *src,char *dest) { HANDLE hFileIn,hFileOut; // int i,j,k; int result=0; unsigned char *buf,*tmpbuf; int srclen,destlen; DWORD nNumberOfBytesRead,nNumberOfBytesWritten; //open src file hFileIn=CreateFile(src,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFileIn==INVALID_HANDLE_VALUE) { printf("open src file %s error\n",src); goto allexit; } //try to open dest file hFileOut=CreateFile(dest,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if(hFileOut==INVALID_HANDLE_VALUE) {//create file error printf("create dest file %s error\n",dest); goto closesrc; } srclen=GetFileSize(hFileIn,0)-4;//file size - head size=data size //read head ReadFile(hFileIn,&destlen,4,&nNumberOfBytesRead,NULL); //printf("\n\nzlz%s %s %d\n\n",src,dest,destlen); if(destlen==0)//file size is 0,then return { result++; goto closedest; } //alloc mem to hold data buf=(unsigned char*)HeapAlloc(hHeap,HEAP_NO_SERIALIZE,srclen); if(buf==NULL) { printf("alloc memory error\n"); goto closedest; } //alloc mem to hold decompressed data tmpbuf=(unsigned char*)HeapAlloc(hHeap,HEAP_NO_SERIALIZE,destlen); if(tmpbuf==NULL) { printf("alloc memory error\n"); goto freebuf; } //read data to buf ReadFile(hFileIn,buf,srclen,&nNumberOfBytesRead,NULL); //decompress if((pDecompressDaily)(buf,srclen,tmpbuf,&destlen)) {//decompress ok,then write to file WriteFile(hFileOut,tmpbuf,destlen,&nNumberOfBytesWritten,0); result++;//set result } else {// decompress error printf("decompress %s error\n",src); } //free tmpbuf HeapFree(hHeap,HEAP_NO_SERIALIZE,tmpbuf); freebuf: HeapFree(hHeap,HEAP_NO_SERIALIZE,buf); closedest: CloseHandle(hFileOut); closesrc: CloseHandle(hFileIn); allexit: return result; } int DecompressMinuteFile(char *src,char *dest) { HANDLE hFileIn,hFileOut; int i; int result=0; unsigned char *buf,*tmpbuf; int srclen,destlen; SHORT head[31*2]; DWORD nNumberOfBytesRead,nNumberOfBytesWritten; //open src file hFileIn=CreateFile(src,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFileIn==INVALID_HANDLE_VALUE) { printf("open src file %s error\n",src); goto allexit; } //try to open dest file hFileOut=CreateFile(dest,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if(hFileOut==INVALID_HANDLE_VALUE) {//if dest does not exist,create a new one printf("create dest file %s error\n",dest); goto closesrc; } //read head ReadFile(hFileIn,head,31*4,&nNumberOfBytesRead,NULL); for(i=0;i<31;i++) { if(head[i*2]!=0) { destlen=head[i*2]; srclen=head[i*2+1]; buf=(unsigned char*)HeapAlloc(hHeap,0,srclen); if(buf==NULL) { goto closedest; } tmpbuf=(unsigned char*)HeapAlloc(hHeap,0,destlen); if(tmpbuf==NULL) { goto freebuf; } ReadFile(hFileIn,buf,srclen,&nNumberOfBytesRead,NULL); if((pDecompressMinute)(buf,srclen,tmpbuf,&destlen)) { WriteFile(hFileOut,tmpbuf,destlen,&nNumberOfBytesWritten,0); } else { printf("decompress %s error\n",src); goto freebuf1; } HeapFree(hHeap,0,tmpbuf); HeapFree(hHeap,0,buf); } } result++; goto closedest; freebuf1: HeapFree(hHeap,0,tmpbuf); freebuf: HeapFree(hHeap,0,buf); closedest: CloseHandle(hFileOut); closesrc: CloseHandle(hFileIn); allexit: return result; }可以解释一下,